Convert temperatures to and from celsius, fahrenheitΒΆ
Convert temperatures to and from celsius, fahrenheit.
Formula : c/5 = (f-32)/9
where c = temperature in celsius
and f = temperature in fahrenheit
Expected output:
60C is 140 in Fahrenheit
45F is 7 in Celsius
temp = input("Input the temperature you like to convert?\
(e.g., 45F, 102C etc.) : ")
degree = int(temp[:-1])
i_convention = temp[-1]
if i_convention.upper() == "C":
result = int(round((9 * degree) / 5 + 32))
o_convention = "Fahrenheit"
elif i_convention.upper() == "F":
result = int(round((degree - 32) * 5 / 9))
o_convention = "Celsius"
else:
print("Input proper convention.")
quit()
# test
print("The temperature in", o_convention, "is", result, "degrees.")
Output:
Input the temperature you like to convert? (e.g., 45F, 102C etc.) : 104f
The temperature in Celsius is 40 degrees.